const Koa = require('koa')
const BodyParser = require('koa-bodyparser')
const Logger = require('koa-logger')
const app = new Koa()

// 全局错误处理
app.use(async (ctx, next) => {
	try {
		await next()
	} catch (err) {
		ctx.body = {
            ret: -1,
            error_code: 'SYSTEM_ERROR',
            error_msg: err.message,
        }
		ctx.status = err.status || 200
	}
})
// router
const Gateway = require('./routes/gateway')

app.use(BodyParser())
app.use(Logger())
app.use(Gateway.routes())
app.listen(3000, () => {
    console.log('the app is running at port 3000')
})